<template>
	<view>
		<view class="content">
			<view class="list">
				<view class="row">
					<view class="title">头像</view>
					<view class="right">
						<view class="tis">
							<!-- <image v-if="user.head_portrait" :src="user.head_portrait" mode=""></image> -->

							<button style="padding: 0;background-color:transparent;line-height:0"
								open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
								<image v-if="user.head_portrait" :src="user.head_portrait" mode="widthFix"></image>
							</button>
						</view>
						<view class="icon xiangyou"></view>
					</view>
				</view>
				<view class="row">
					<view class="title">昵称</view>

					<view class="right">
						<view class="tis" v-if="!user.name">
							<input  type="nickname" @blur="bindblur" value="" placeholder="请输入昵称" />
						</view>
						<view v-else  class="tis">{{user.name}}</view>
						<view class="icon xiangyou">

						</view>
					</view>
				</view>
				<!-- 	<view class="row">
					<view class="title">个性签名</view>
					<view class="right"><view class="tis">这人太懒了，什么都不写</view><view class="icon xiangyou"></view></view>
				</view> -->
				<view class="row">
					<view class="title">收货地址</view>
					<view class="right">
						<view class="tis"></view>
						<view class="icon xiangyou"></view>
					</view>
				</view>
				<view class="row">
					<view class="title">账户安全</view>
					<view class="right">
						<view class="tis"></view>
						<view class="icon xiangyou"></view>
					</view>
				</view>
			</view>
			<view class="list">
				<view class="row">
					<view class="title">通知提醒</view>
					<view class="right">
						<view class="tis"></view>
						<view class="icon xiangyou"></view>
					</view>
				</view>
				<!-- 	<view class="row">
					<view class="title">支付设置</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view> -->
				<!-- 	<view class="row">
					<view class="title">通用</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view> -->
			</view>
			<view class="list">
				<!-- 	<view class="row">
					<view class="title">版本升级</view>
					<view class="right"><view class="tis">v1.0.0</view><view class="icon xiangyou"></view></view>
				</view> -->
				<!-- <view class="row">
					<view class="title">清除缓存</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view> -->
				<!-- 		<view class="row">
					<view class="title">问题反馈</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view> -->
				<view class="row">
					<view class="title">关于商城</view>
					<view class="right">
						<view class="tis"></view>
						<view class="icon xiangyou"></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {}
			};
		},
		onShow() {
			this.getUser();
		},
		methods: {
			//授权头像
			onChooseAvatar(e) {
				var that = this;
				this.user.head_portrait = e.detail.avatarUrl
				console.log(this.user.head_portrait)
				uni.uploadFile({
					url: 'https://hh.sc.yifckj.com/api/file/upload',
					filePath: this.user.head_portrait,
					name: "file",
					header: {
						Authorization: uni.getStorageSync('token')
					},
					formData: {
						type: "2"
					},
					success: (res) => {
						console.log(res)
					},
					fail(err) {
						console.error('上传失败');
						console.error(err);

						// 错误处理逻辑
					}
				})
				// that.$http.post('me/setInfo',{
				// 	head_portrait:e.detail.avatarUrl
				// }).then((res)=>{
				// 	console.log(res);
				// 	this.getUser()
				// })
			},
			//授权昵称
			bindblur(e) {
				var that = this;
				console.log(e.detail.value)
				this.user.name = e.detail.value
				that.$http.post('me/setInfo', {
					name: e.detail.value
				}).then((res) => {
					console.log(res);
					this.getUser()
				})
			},
			getUser() {
				var that = this;
				that.$http.post('me/userInfo', {
					code: that.code
				}).then((res) => {
					this.user = res.data.user
				});
			},
			showType(tbIndex) {
				this.tabbarIndex = tbIndex;
				this.list = this.orderList[tbIndex];
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f3f3f3;
	}

	.icon {
		font-size: 30upx;

	}

	button::after {
		border: none;
	}

	.content {
		padding-bottom: 20upx;

		.list {
			width: 96%;
			padding-left: 4%;
			background-color: #fff;
			margin-bottom: 20upx;

			.row {
				widows: 100%;
				min-height: 90upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: solid 1upx #eee;

				&:last-child {
					border-bottom: none;
				}

				.title {
					font-size: 32upx;
					color: #333;
				}

				.right {
					display: flex;
					align-items: center;
					color: #999;

					.tis {
						font-size: 26upx;
						margin-right: 5upx;
						max-height: 120upx;

						image {
							width: 100upx;
							height: 100upx;
							border-radius: 100%;
							margin: 10upx 0;
						}
					}

					.icon {
						width: 40upx;
						color: #cecece;
					}
				}

			}
		}
	}
</style>